package com.ibeeking.found.report.service.common.bo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ibeeking.found.report.service.common.constant.CommonConstant;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1;
    private T result;
    @JsonIgnore
    private String onlTable;
    private boolean success = true;
    private String message = "";
    private Integer code = 0;
    private long timestamp = System.currentTimeMillis();

    @Deprecated
    public static Result<Object> OK() {
        Result<Object> result = new Result<>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SC_OK_200);
        result.setMessage("成功");
        return result;
    }

    @Deprecated
    public static Result<Object> OK(String msg) {
        Result<Object> result = new Result<>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SC_OK_200);
        result.setMessage(msg);
        return result;
    }

    @Deprecated
    public static Result<Object> setOKInfo(Object data) {
        Result<Object> result = new Result<>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SC_OK_200);
        result.setResult(data);
        return result;
    }

    public static <T> Result<T> SUCCESS() {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SC_OK_200);
        return result;
    }

    public static <T> Result<T> SUCCESS(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SC_OK_200);
        result.setResult(data);
        return result;
    }

    public static <T> Result<T> SUCCESS(String msg, T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SC_OK_200);
        result.setMessage(msg);
        result.setResult(data);
        return result;
    }

    public static <T> Result<T> FAIL(String msg, T data) {
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(CommonConstant.SC_OK_200);
        result.setMessage(msg);
        result.setResult(data);
        return result;
    }

    public static Result<Object> error(String msg) {
        return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500.intValue(), msg);
    }

    public static Result<Object> error(int code, String msg) {
        Result<Object> result = new Result<>();
        result.setCode(Integer.valueOf(code));
        result.setMessage(msg);
        result.setSuccess(false);
        return result;
    }

    public static Result<Object> noauth(String msg) {
        return error(CommonConstant.SC_JEECG_NO_AUTHZ.intValue(), msg);
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof Result)) {
            return false;
        }
        Result result = (Result) o;
        if (!result.canEqual(this) || isSuccess() != result.isSuccess() || getTimestamp() != result.getTimestamp()) {
            return false;
        }
        Integer code = getCode();
        Integer code2 = result.getCode();
        if (code == null) {
            if (code2 != null) {
                return false;
            }
        } else if (!code.equals(code2)) {
            return false;
        }
        String message = getMessage();
        String message2 = result.getMessage();
        if (message == null) {
            if (message2 != null) {
                return false;
            }
        } else if (!message.equals(message2)) {
            return false;
        }
        T result2 = getResult();
        Object result3 = result.getResult();
        if (result2 == null) {
            if (result3 != null) {
                return false;
            }
        } else if (!result2.equals(result3)) {
            return false;
        }
        String onlTable = getOnlTable();
        String onlTable2 = result.getOnlTable();
        return onlTable == null ? onlTable2 == null : onlTable.equals(onlTable2);
    }

    protected boolean canEqual(Object other) {
        return other instanceof Result;
    }

    @Override
    public int hashCode() {
        int i = (1 * 59) + (isSuccess() ? 79 : 97);
        long timestamp = getTimestamp();
        int i2 = (i * 59) + ((int) ((timestamp >>> 32) ^ timestamp));
        Integer code = getCode();
        int hashCode = (i2 * 59) + (code == null ? 43 : code.hashCode());
        String message = getMessage();
        int hashCode2 = (hashCode * 59) + (message == null ? 43 : message.hashCode());
        T result = getResult();
        int hashCode3 = (hashCode2 * 59) + (result == null ? 43 : result.hashCode());
        String onlTable = getOnlTable();
        return (hashCode3 * 59) + (onlTable == null ? 43 : onlTable.hashCode());
    }

    @Override
    public String toString() {
        return "Result(success=" + isSuccess() + ", message=" + getMessage() + ", code=" + getCode() + ", result=" + getResult() + ", timestamp=" + getTimestamp() + ", onlTable=" + getOnlTable() + ")";
    }

    public boolean isSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getResult() {
        return this.result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public Result<T> success(String message) {
        this.message = message;
        this.code = CommonConstant.SC_OK_200;
        this.success = true;
        return this;
    }

    public Result<T> error500(String message) {
        this.message = message;
        this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
        this.success = false;
        return this;
    }

    public String getOnlTable() {
        return this.onlTable;
    }

    @JsonIgnore
    public void setOnlTable(String onlTable) {
        this.onlTable = onlTable;
    }
}
